package secure;

public class Demo4 {
    public static int a = 0;
    public static boolean flag = false;
    public static void main(String[] args) {
        while (true){
            // 修改 a 和 flag
            Thread t1 = new Thread(()->{
                a = 1;
                flag = true;
            });
            // 查看击中情况
            Thread t2 = new Thread(()->{

                    if(flag){
                        if(a == 0)
                            System.out.println("击中");

                }
            });
            t1.start();
            t2.start();
            try {
                t1.join();
                t2.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            // 重置 a 和 flag
            a = 0;
            flag = false;
        }

    }
}
